var Generator = require('yeoman-generator');

module.exports = class extends Generator {
  // The name `constructor` is important here
  constructor(args, opts) {
    // Calling the super constructor is important so our generator is correctly set up
    super(args, opts);
    // Next, add your custom code
    // this.option('babel'); // This method adds support for a `--babel` flag
  }

  async initPackage() {
    let answers = await this.prompt([
      {
        type: 'input',
        name: 'name',
        message: 'Your project name',
        default: this.appname // Default to current folder name
      }
    ])

    const pkgJson = {
      "name": answers.name,
      "version": "0.1.0",
      "description": "",
      "main": "main.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "dependencies": {
        // "core-js": "^3.6.5",
        // "vue": "^3.0.0",
        // "vue-loader": "15.9.8",
        // "vue-template-compiler": "2.6.14"
      },
      "devDependencies": {
        // "@babel/core": "^7.16.0",
        // "babel-eslint": "^10.1.0",
        // "babel-loader": "^8.2.3",
        // "eslint": "^6.7.2",
        // "eslint-plugin-vue": "^7.0.0",
        // "webpack": "^5.61.0",
        // "webpack-cli": "^4.9.1",
      },
      /* "eslintConfig": {
        "root": true,
        "env": {
          "node": true
        },
        "extends": [
          "plugin:vue/vue3-essential",
          "eslint:recommended"
        ],
        "parserOptions": {
          "parser": "babel-eslint"
        },
        "rules": {}
      },
      "browserslist": [
        "> 1%",
        "last 2 versions",
        "not dead"
      ] */
    };

    // Extend or create package.json file in destination path
    this.fs.extendJSON(this.destinationPath('package.json'), pkgJson);
    Object.assign(Generator.prototype, require('yeoman-generator/lib/actions/install'))
    this.npmInstall(["vue"], { "save-dev": false });
    this.npmInstall(["webpack", "vue-loader", "vue-style-loader",
      "css-loader", "vue-template-compiler", "copy-webpack-plugin"], { "save-dev": true });

  }

  copyFiles() {
    this.fs.copyTpl(
      this.templatePath('webpack.config.js'),
      this.destinationPath('webpack.config.js'),
      {}
    );
    this.fs.copyTpl(
      this.templatePath('main.js'),
      this.destinationPath('src/main.js'),
      {}
    );
    this.fs.copyTpl(
      this.templatePath('App.vue'),
      this.destinationPath('src/App.vue'),
      {}
    );
    this.fs.copyTpl(
      this.templatePath('HelloWorld.vue'),
      this.destinationPath('src/components/HelloWorld.vue'),
      {}
    );
    this.fs.copyTpl(
      this.templatePath('index.html'),
      this.destinationPath('src/index.html'),
      { title: 'demo-vue' }
    );

  }

};